//*****************************************************************************
// JFab (http://code.google.com/p/jfab)
// Copyright (c) 2011-2012 JFab.org
// Admin jfab@jeffreythompson.net
//
// See the file "LICENSE.txt" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//*****************************************************************************

package org.jfab.swingui.editpane;

import javax.swing.JTextField;

import org.jfab.core.model.CGParameter;

/**
 * Provides an edit pane for a code generator parameter.
 */
public final class CGParameterEditPane extends CGObjectEditPane<CGParameter>
{
    /** Serial version UID. */
    private static final long serialVersionUID = 1L;

    /** Type widget. */
    private JTextField _typeUI;

    /**
     * @param cgParameter Code generator parameter.
     */
    public CGParameterEditPane(final CGParameter cgParameter)
    {
        super(cgParameter);
    }

    @Override
    public final void applyChanges()
    {
        super.applyChanges();

        final CGParameter subject = getSubjectObject();

        subject.setType(getCgTypeAdapter().unmarshal(_typeUI.getText()));
    }

    @Override
    protected final void createWidgets()
    {
        super.createWidgets();

        _typeUI = createTextField();
    }

    @Override
    protected final void fillPanel()
    {
        super.fillPanel();

        bindAndAdd("type", _typeUI, getCgTypeAdapter());
    }

    @Override
    protected final void fillWidgets()
    {
        super.fillWidgets();

        final CGParameter subject = getSubjectObject();

        _typeUI.setText(getCgTypeAdapter().marshal(subject.getType()));
    }
}
